<%--
  Created by IntelliJ IDEA.
  User: 林龙
  Date: 2024/12/16
  Time: 下午3:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%
    String DB_URL = "jdbc:mysql://localhost:3306/game"; // 替换为你的数据库信息
    String USER = "root"; // 替换为你的数据库用户名
    String PASS = "1234"; // 替换为你的数据库密码

    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);

        String sql = "SELECT * FROM query_logs ORDER BY id DESC"; // 查询日志
        PreparedStatement stmt = conn.prepareStatement(sql);
        ResultSet rs = stmt.executeQuery();

        // 输出日志内容
        while (rs.next()) {
            int id = rs.getInt("id");
            String operation_type = rs.getString("operation_type");
            String operation_content = rs.getString("operation_content");
            String username = rs.getString("username");
            String ip_address = rs.getString("ip_address");
            String created_at = rs.getString("created_at");
            String result = rs.getString("result");
%>
<div class="log-entry">
    <p><strong>ID:</strong> <%= id %></p>
    <p><strong>操作类型:</strong> <%= operation_type %></p>
    <p><strong>操作内容:</strong> <%= operation_content %></p>
    <p><strong>用户名:</strong> <%= username %></p>
    <p><strong>IP 地址:</strong> <%= ip_address %></p>
    <p><strong>创建时间:</strong> <%= created_at %></p>
    <p><strong>结果:</strong> <%= result %></p>
    <hr /> <!-- 分隔线 -->
</div>
<%
        }

        // 关闭数据库连接
        rs.close();
        stmt.close();
        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
        out.println("无法加载日志: " + e.getMessage());
    }
%>